package com.mosband.genecharts;

import com.alibaba.fastjson.JSON;
import com.mosband.genecharts.comm.Cons;
import com.mosband.genecharts.util.EchartsUtil;
import com.mosband.genecharts.util.FreemarkerUtil;

import java.util.HashMap;

public class Line01 {
    public static void main(String[] args) throws Exception {

        String ftlName = "line01";
        // 变量
        String[] categories = new String[] {"1日","2日","3日","4日","5日","6日","7日","8日","9日","10日","11日","12日","13日","14日","15日","16日","17日","18日","19日","20日","21日","22日","23日","24日","25日","26日","27日","28日","29日","30日","31日"};
        double [] incomeTotal = new double[] {26,11.1,12.1,41,14.1,15.1,16.1,32,18.1,19.1,20.1,21.1,22.1,23.1,24.1,25.1,26.1,27.1,28.1,29.1,30.1,31.1,32.1,33.1,34.1,35.1,36.1,37.1,38.1,39.1,40.1};
        double[] incomeSDk = new double[] {1.2,8,3.2,4.2,5.2,6.2,7.2,8.2,9.2,10.2,11.2,19,13.2,14.2,15.2,16.2,17.2,12,19.2,20.2,21.2,22.2,23.2,1,25.2,26.2,27.2,28.2,29.2,30.2,31.2};
        double[] incomeADX = new double[] {24.8,3.1,8.9,36.8,8.9,8.9,8.9,23.8,8.9,8.9,8.9,2.1,8.9,8.9,8.9,8.9,8.9,15.1,8.9,8.9,8.9,8.9,8.9,32.1,8.9,8.9,8.9,8.9,8.9,8.9,8.9};

        // 模板参数
        HashMap<String, Object> datas = new HashMap<>();
        datas.put("categories", JSON.toJSONString(categories));
        datas.put("incomeTotal", JSON.toJSONString(incomeTotal));
        datas.put("incomeSDk", JSON.toJSONString(incomeSDk));
        datas.put("incomeADX", JSON.toJSONString(incomeADX));


        // 生成option字符串
        String option = FreemarkerUtil.generateString(ftlName+".ftl", "", datas);
        System.out.println(option);

        // 根据option参数
        String base64 = EchartsUtil.generateEchartsBase64(option,null,null);

        System.out.println("BASE64:" + base64);
        EchartsUtil.generateImage(base64, Cons.getPathOutPath(Cons.path_project,ftlName));
    }

}
